package com.example.hyw.szysteam.presenter;

import android.view.View;

import com.example.hyw.szysteam.POJO.HttpResult;
import com.example.hyw.szysteam.POJO.User;
import com.example.hyw.szysteam.model.UserModel;
import com.example.hyw.szysteam.view.RegistDialog;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.Subject;

/**
 * Created by HYW on 2018/6/4.
 */

public class RegistPresenter {
    private UserModel userModel=new UserModel();
    private RegistDialog registDialog;

    public RegistPresenter(RegistDialog registDialog){
        this.registDialog=registDialog;
    }

    public void toRegist(final String email,final String password){
        userModel.regist(email,password)
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HttpResult<User>>() {
                    @Override
                    public void accept(HttpResult<User> userHttpResult) throws Exception {
                        if(userHttpResult.getResult()==HttpResult.RESULT_SUCCESS){
                            registDialog.registSuccess();
                        }else {
                            registDialog.registFail();
                        }
                    }
                });
    }
}
